`
https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag/
`

/**
 * @param {number[]} nums
 * @param {number} maxOperations
 * @return {number}
 */
var minimumSize = function (nums, maxOperations) {
  // 要实现每个袋子里最多放 m 个球，需要的操作数是否 <= maxOperations
  const check = (m) => {
    let opera = 0
    for (const x of nums) {
      opera += Math.ceil(x / m) - 1
      if (opera > maxOperations) return false
    }
    return true
  }

  let left = 0, right = Math.max(...nums)
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (check(mid)) {
      right = mid
    } else {
      left = mid
    }
  }
  return right
};